home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-04-28 | 8.5 KB | 292 lines | [TEXT/MPS ] |
- /*
- File: AppleEventHandling.cp
-
- Contains: Minimalist support for the required and Display Manager AppleEvents
- We also support openning and printing “LetterSpec” documents for AOCE.
-
- To really support AppleScript™, we’ll need to do ALOT more work in here.
-
- Written by: Dave Falkenburg
-
- Copyright: © 1993-94 by Dave Falkenburg, all rights reserved.
-
- Change History (most recent first):
-
- <5> 11/16/94 DRF Add StandardAEIdleProc for people who like using AESend with
- kAEWaitReply.
- <4> 11/12/94 DRF Removed extra #include.
- <3> 9/27/94 DRF AppLib.h is now Sprocket.h
- <2> 9/4/94 DRF Added stub Text Services AppleEvent handlers.
- */
-
- #include "Sprocket.h"
-
- #include <AppleEvents.h>
- #include <Errors.h>
- #include <Displays.h> // for Display Manager AppleEvent constants
- #include <OCEStandardMail.h> // for LetterSpec
-
- #if qInlineInputAware
- #include <TextServices.h>
- #endif
-
- #include "AppleEventHandling.h"
-
- static pascal Boolean StandardAEIdleProc(EventRecord *theEvent, long *sleepTime, RgnHandle *mouseRgn);
-
-
- void
- InstallAppleEventHandlers(void)
- {
- // It’s probably more efficient to use a table to install these handlers…
-
- (void) AEInstallEventHandler(kCoreEventClass,kAEOpenApplication,NewAEEventHandlerProc(HandleOpenApplication),0,false);
- (void) AEInstallEventHandler(kCoreEventClass,kAEOpenDocuments,NewAEEventHandlerProc(HandleOpenDocuments),0,false);
- (void) AEInstallEventHandler(kCoreEventClass,kAEPrintDocuments,NewAEEventHandlerProc(HandlePrintDocuments),0,false);
- (void) AEInstallEventHandler(kCoreEventClass,kAEQuitApplication,NewAEEventHandlerProc(HandleQuitApplication),0,false);
-
- // regardless of whether or not we have the display manager, go ahead and register an AppleEvent handler
- (void) AEInstallEventHandler(kCoreEventClass,kAESystemConfigNotice,NewAEEventHandlerProc(HandleSystemConfigNotice),0,false);
-
- #if qInlineInputAware
- if (gHasTextServices)
- {
- (void) AEInstallEventHandler(kTextServiceClass,kUpdateActiveInputArea,NewAEEventHandlerProc(HandleTextServicesUpdateActiveInputArea),0,false);
- (void) AEInstallEventHandler(kTextServiceClass,kPos2Offset,NewAEEventHandlerProc(HandleTextServicesPos2Offset),0,false);
- (void) AEInstallEventHandler(kTextServiceClass,kOffset2Pos,NewAEEventHandlerProc(HandleTextServicesOffset2Pos),0,false);
- // we don’t need to handle <kTextServiceClass,kShowHideInputWindow> events
- }
- #endif
- }
-
-
- OSErr
- CheckAppleEventForMissingParams(AppleEvent *theAppleEvent)
- {
- DescType returnedType;
- Size actualSize;
- OSErr err;
-
- err = AEGetAttributePtr(theAppleEvent,keyMissedKeywordAttr,typeWildCard,
- &returnedType,nil,0,&actualSize);
-
- if (err == errAEDescNotFound) // If we couldn’t find the error attribute
- return noErr; // everything is ok, return noErr
-
- if (err == noErr) // We found an error attribute, so
- return errAEEventNotHandled; // tell the client we ignored the event
-
- return err; // Something else happened, return it
- }
-
-
- AEIdleUPP StandardAEIdleUPP = NewAEIdleProc(StandardAEIdleProc);
-
- static pascal Boolean
- StandardAEIdleProc(EventRecord *theEvent, long * /* sleepTime */, RgnHandle * /* mouseRgn */)
- {
- HandleEvent(theEvent); // First, always hand event off to our event handling code
- return false;
- }
-
-
- OSErr
- ForEachDocumentInList(AEDescList documentList,EachDocumentProcPtr documentProc,void * documentParam)
- {
- long documentCount,documentIndex;
- DescType returnedType;
- Size actualSize;
- LetterDescriptor theLetterDesc;
- AEKeyword keyword;
- OSErr err;
-
- if ((err = AECountItems(&documentList,&documentCount)) != noErr)
- return err;
-
- for (documentIndex=1; documentIndex <= documentCount; documentIndex++)
- {
- // What kind of document is it?
- if ((err = AESizeOfNthItem(&documentList,documentIndex,&returnedType,&actualSize)) != noErr)
- return err;
-
- // Is it an AOCE letter?
- if (returnedType == typeLetterSpec)
- {
- // It’s a letter
- theLetterDesc.onDisk = false;
- err = AEGetNthPtr(&documentList,documentIndex,typeLetterSpec,&keyword,&returnedType,
- (Ptr) &theLetterDesc.u.mailboxSpec, sizeof(theLetterDesc.u.mailboxSpec),&actualSize);
- }
- else
- {
- // It’s just a normal document file
- theLetterDesc.onDisk = true;
- err = AEGetNthPtr(&documentList,documentIndex,typeFSS,&keyword,&returnedType,
- (Ptr) &theLetterDesc.u.fileSpec,sizeof(theLetterDesc.u.fileSpec),&actualSize);
- }
-
- if (err == noErr)
- (*documentProc)(&theLetterDesc,documentParam);
- else
- break;
- }
-
- return err;
- }
-
-
- pascal OSErr
- HandleOpenApplication(AppleEvent *theAppleEvent,AppleEvent * /*reply*/,long /*refCon*/)
- {
- OSErr err;
-
- if ((err = CheckAppleEventForMissingParams(theAppleEvent)) != noErr)
- return err;
-
- return(CreateNewDocument());
- }
-
-
- pascal OSErr
- HandleOpenDocuments(AppleEvent *theAppleEvent,AppleEvent * /*reply*/,long /*refCon*/)
- {
- AEDescList documentList;
- OSErr err;
-
- if ((err = AEGetParamDesc(theAppleEvent,keyDirectObject,typeAEList,&documentList)) != noErr)
- return err;
-
- if ((err = CheckAppleEventForMissingParams(theAppleEvent)) != noErr)
- return err;
-
- err = ForEachDocumentInList(documentList,&OpenDocument,nil);
- (void) AEDisposeDesc(&documentList);
- return err;
- }
-
-
- pascal OSErr
- HandlePrintDocuments(AppleEvent *theAppleEvent,AppleEvent * /*reply*/,long /*refCon*/)
- {
- AEDescList documentList;
- #if qUseQuickDrawGX
- AEDescList desktopPrinterList;
- FSSpec thePrinterFSSpec;
- Boolean draggedToDesktopPrinter = false;
- #endif
- OSErr err;
-
- if ((err = AEGetParamDesc(theAppleEvent,keyDirectObject,typeAEList,&documentList)) != noErr)
- return err;
-
- #if qUseQuickDrawGX
- if (noErr == AEGetAttributeDesc(theAppleEvent,keyOptionalKeywordAttr,typeAEList,&desktopPrinterList))
- draggedToDesktopPrinter = true;
- #endif
-
- if ((err = CheckAppleEventForMissingParams(theAppleEvent)) != noErr)
- return err;
-
- #if qUseQuickDrawGX
- if (draggedToDesktopPrinter)
- {
- DescType returnedType;
- Size actualSize;
- AEKeyword keyword;
-
- err = AEGetNthPtr(&desktopPrinterList,1,typeFSS,&keyword,&returnedType,
- (Ptr) &thePrinterFSSpec,sizeof(thePrinterFSSpec),&actualSize);
-
- (void) AEDisposeDesc(&desktopPrinterList);
- }
- err = ForEachDocumentInList(documentList,&PrintDocument,draggedToDesktopPrinter ? &thePrinterFSSpec : NULL);
- (void) AEDisposeDesc(&documentList);
- #else
- err = ForEachDocumentInList(documentList,&PrintDocument,nil);
- #endif
-
- return err;
- }
-
-
- pascal OSErr
- HandleQuitApplication(AppleEvent *theAppleEvent,AppleEvent * /* reply */,long /* refCon */)
- {
- OSErr err;
-
- if ((err = CheckAppleEventForMissingParams(theAppleEvent)) != noErr)
- return err;
-
- gDone = QuitApplication();
-
- if (gDone)
- return noErr;
- else
- return userCanceledErr;
- }
-
-
- ////////////////////////////////////////////////////////////////////////
- //
- // Display Manager Suite is “Under Construction”
- //
- // To Do: Check ERS for Display Manager events
-
- pascal OSErr
- HandleSystemConfigNotice(AppleEvent *theAppleEvent,AppleEvent * /* reply */,long /* refCon */)
- {
- AEDescList displayList;
- long displayCount,displayIndex;
- OSErr err;
-
- DebugStr((StringPtr) "\pGot a Display Manager Event!");
-
- if ((err = AEGetParamDesc(theAppleEvent,kAEDisplayNotice,typeAEList,&displayList)) != noErr)
- return err;
-
- if ((err = CheckAppleEventForMissingParams(theAppleEvent)) != noErr)
- return err;
-
- if ((err = AECountItems(&displayList,&displayCount)) != noErr)
- return err;
-
- for (displayIndex = 1; displayIndex<=displayCount; displayIndex++)
- {
- DebugStr((StringPtr) "\pProcessing a display");
-
- // Gather up all the old and new display rectangles into an oldDeskRegion and a newDeskRegion
- }
-
- // run through all windows calling keeping all windows which were onscreen in the oldDeskRegion
- // onscreen in the new world. We should really be calling a method to do this so that windows
- // can individually deal with things in a manner which they can override.
-
-
- return errAEEventNotHandled; // we really don’t handle this yet...
- }
-
- #if qInlineInputAware
-
- pascal OSErr
- HandleTextServicesUpdateActiveInputArea(AppleEvent *theAppleEvent,AppleEvent *reply,long refCon)
- {
- DebugStr("\pTextServicesUpdateActiveInputArea");
- return errAEEventNotHandled; // we really don’t handle this yet...
- }
-
- pascal OSErr
- HandleTextServicesPos2Offset(AppleEvent *theAppleEvent,AppleEvent *reply,long refCon)
- {
- DebugStr("\pTextServicesPos2Offset");
- return errAEEventNotHandled; // we really don’t handle this yet...
- }
-
- pascal OSErr
- HandleTextServicesOffset2Pos(AppleEvent *theAppleEvent,AppleEvent *reply,long refCon)
- {
- DebugStr("\pTextServicesOffset2Pos");
- return errAEEventNotHandled; // we really don’t handle this yet...
- }
-
- #endif
-